<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Quản lý sản phẩm
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>Admins</a></li>
        <li><a href="#">Sản phẩm</a></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <!-- column -->
            <div class="col-md-12">
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">Danh sách sản phẩm</h3>
                  <div class="more-action">
                        <a href="<?php echo DOMAIN.'/'; ?>application.php?mod=mod_admin&control=Products&task=add" class="btn btn-block btn-primary">Thêm</a>
                        <a href="" class="btn btn-block btn-danger">Xóa tất cả</a>
                  </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                <?php
                if(count($getAllPro) > 0 )
                {
                ?>                
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>No.</th>
                        <th>Tên SP</th>
                        <th>Mã SP</th>
                        <th>Danh Mục</th>
                        <th>Giá</th>
                        <th>Giá Sale</th>
                        <th>Bảo hành</th>
                        <th>Ảnh</th>
                        <th>Thao tác</th>
                      </tr>
                    </thead>
                    <tbody>
                        <?php
                        $count = 1;
                        foreach($getAllPro as $rows)
                        {
                        ?>                    
                      <tr id="row_<?php echo $rows['ID_PRODUCT']; ?>">
                        <td><?php echo $count; ?></td>
                        <td><a href="<?php echo DOMAIN.'/'; ?>application.php?mod=mod_admin&control=Products&task=edit&id=<?php echo $rows['ID_PRODUCT']; ?>"><?php echo $rows['NAME_PRODUCT']; ?></a></td>
                        <td><?php echo $rows['CODE_PRODUCT']; ?></td>
                        <td><?php echo $rows['CAT_NAME']; ?></td>
                        <td><?php echo $rows['PRICE_PRODUCT']; ?></td>
                        <td><?php echo $rows['PRICESALE_PRODUCT']; ?></td>
                        <td><?php echo $rows['BH_PRODUCT']; ?></td>
                        <td>
                            <?php
                                if($rows['PHOTO_PRODUCT']!='')
                                {
                                ?>
                                <img width="50" src="<?php echo DOMAIN.$rows['PHOTO_PRODUCT']; ?>" />
                                <?php
                                }
                                else
                                {
                                ?>
                                <img width="50" src="<?php echo DOMAIN."/access/images/no-images.jpg"; ?>" />
                                <?php
                                }
                            ?>
                        </td>
                        <td><a id="<?php echo $rows['ID_PRODUCT']; ?>" class="delete"><i class="glyphicon glyphicon-remove"></i></a></td>
                      </tr>
                        <?php
                        $count ++;
                        }
                        ?>                       
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>No.</th>
                        <th>Tên SP</th>
                        <th>Mã SP</th>
                        <th>Danh Mục</th>
                        <th>Giá</th>
                        <th>Giá Sale</th>
                        <th>Ảnh</th>
                        <th>Thao tác</th>
                      </tr>
                    </tfoot>
                  </table>
                <?php
                }
                else
                {
                    echo "Hiện tại chưa có sản phẩm nào";
                }
                ?>                  
                </div><!-- /.box-body -->
              </div><!-- /.box -->    
        </div>
              <script>
              $(document).ready(function(){
                    $("a.delete").click(function(event){
                        event.preventDefault();
                        var r = confirm("Bạn có muốn xóa?");
                        if (r == true) {
                            var id = $(this).attr('id');
                            var url = "<?php echo DOMAIN.'/'; ?>" + "application.php";
                            var data = {
                              "mod": "mod_admin",
                              "control": "Products",
                              "task": "del",
                              "id": id,
                            };                            
                    		$.ajax({
                    			url: url,
                    			type: 'POST',
                    			cache: false,
                    			data: data,
                    			success: function(string){
      			                   $("#row_"+id).remove();
                    			},
                    			error: function (){
                    				alert('Có lỗi xảy ra');
                    			}
                    		});                                                       
                        }                       
                    });
              });
              </script>         
    </section><!-- /.content -->    
</div><!-- /.content-wrapper -->